package com.project.microweatherservice.config;

import com.project.microweatherservice.job.WeatherDataSyncJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfiguration {

    @Bean
    public JobDetail weatherDataSyncJobDetail() {
        return JobBuilder.newJob(WeatherDataSyncJob.class)
                .withIdentity("weatherDataSyncJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger weatherDataSyncTrigger() {
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInMinutes(30).repeatForever();
        return TriggerBuilder.newTrigger()
                .withIdentity("weatherDataSyncTrigger")
                .forJob(weatherDataSyncJobDetail())
                .withSchedule(scheduleBuilder)
                .build();
    }
}
